<script>


export default ({
  name: "MyFooter",
  props:{
    todoList:Array
  },
  computed:{
    //任务总数
    total(){
      return this.todoList.length
    },
    //已完成的任务数
    doneTotal(){
      return this.todoList.reduce((pre, todo) => pre + (todo.done ? 1 : 0),0);
    },
    //是否全选
    isAll:{
      get(){
        return this.total > 0 && this.total === this.doneTotal
      },
      set(done){
        this.$emit("checkAllTodo",done)
      }
    }
  },
  methods:{
    //清除已完成任务
    clearDone(){
      this.$emit("clearDoneTodo")
    }
  }
})
</script>

<template>
  <div class="todo-footer" v-show="total">
    <label>
      <input type="checkbox" v-model="isAll"/>
    </label>
    <span >
      <span>已完成{{doneTotal}}</span> / 全部{{total}}
    </span>
    <button class="btn btn-danger" @click = "clearDone">清除已完成任务</button>
  </div>
</template>

<style scoped>
.todo-footer {
  height: 40px;
  line-height: 40px;
  margin-top: 5px;
  padding-left: 6px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>